/**
 * 给定一个 没有重复 数字的序列，返回其所有可能的全排列。
  示例:
  输入: [1,2,3]
  输出:
  [
    [1,2,3],
    [1,3,2],
    [2,1,3],
    [2,3,1],
    [3,1,2],
    [3,2,1]
  ]
 */
const noRepeatList = (nums) => {
  const result = [];
  const len = nums.length;

  for (let i = 0; i < len; i++) {
    rec([nums[i]]);
  }

  return result;

  function rec(arr) {
    if (arr.length === len) {
      result.push(arr);
      return;
    }

    for (let i = 0; i < len; i++) {
      // if (arr.includes(nums[i])) continue;
      if (arr.includes(nums[i])) {
        continue;
      }
      let list = arr.slice();
      list.push(nums[i]);

      rec(list);
    }
  }
};

console.log(noRepeatList([1, 2, 3]));
